#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: about.py
# Author: Tomás Vírseda
# License: GPL v3
# Description:  The About Dialog window.

import webbrowser

import gtk

from vazaarlib.constants import *
from vazaarlib.namespaces import PIMO


class AboutDialog(gtk.AboutDialog):
    def __init__(self, gui):
        gtk.AboutDialog.__init__(self)
        self.gui = gui
        self.icon = self.gui.icons.get_icon_by_name(PIMO['Collection'])
        self.set_name(VAZAAR_NAME)
        self.set_version(VAZAAR_VERSION)
        self.set_copyright(VAZAAR_COPYRIGHT)
        self.set_comments(VAZAAR_SHORT_DESCRIPTION)
        try:
            f = open(ROOT_DIR + '/COPYING', 'r')
            copying = f.read()
            f.closed
        except:
            copying = VAZAAR_LICENSE

        self.set_license(copying);
        self.set_website(VAZAAR_WEBSITE)
        self.set_website_label(VAZAAR_WEBSITE_LABEL)
        self.set_authors(VAZAAR_AUTHORS)
        #logo = util.get_pixbuf(LOGO)
        self.set_logo(self.icon)
        self.set_icon(self.icon)
        gtk.about_dialog_set_url_hook(self.open_url, None)

    def open_url(self, dialog, link, ignored):
        try:
            webbrowser.open_new_tab(link)
        except:
            pass

    def run(self):
        self.show_all()
        gtk.AboutDialog.run(self)
        self.destroy()
